<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2024/9/2
  Time: 下午2:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="Medicamp Responsive Bootstrap Template">
    <meta name="keywords" content="Pixel">
    <meta name="author" content="rkwebdesigns">
    <!-- Site Title   -->
    <title>科室管理</title>
    <!-- Bootstrap -->
    <link href="${pageContext.request.contextPath}/static/css/bootstrap.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/css/bootstrap-dropdownhover.min.css" rel="stylesheet">
    <!-- Fonts Awesome -->
    <link href="${pageContext.request.contextPath}/static/css/font-awesome.min.css" rel="stylesheet">
    <!-- Google Fonts -->
    <link href='https://fonts.googleapis.com/css?family=Open+Sans:400,300,300italic,800italic,800,600italic,600,400italic,700,700italic' rel='stylesheet' type='text/css'>
    <!-- animate Effect -->
    <link href="${pageContext.request.contextPath}/static/css/animate.css" rel="stylesheet">
    <!-- Main CSS -->
    <link href="${pageContext.request.contextPath}/static/css/style.css" rel="stylesheet">
    <!-- Responsive CSS -->
    <link href="${pageContext.request.contextPath}/static/css/responsive.css" rel="stylesheet">
</head>
<body>

<section id="inner-title" class="inner-title">
    <div class="container">
        <div class="row">
            <div class="col-md-6 col-lg-6"><h2>科室信息管理</h2></div>

        </div>

    </div>



</section>
<section id="section18" class="section-margine">
    <div class="container">
<div class="section18">
    <div class="row">
        <!--工具栏-->
        <div class="pull-left">
            <div class="form-group form-inline">
                <div class="btn-group">
                    <button type="button" class="btn btn-default" id="toadd" title="新建"><i class="fa fa-file-o"></i> 新增</button>
                    <button type="button" class="btn btn-default" onclick="toDel()" title="删除"><i class="fa fa-trash-o"></i> 删除</button>
                    <button type="button" class="btn btn-default" onclick="update()"  title="开启"><i class="fa fa-check"></i> 修改</button>
                </div>
            </div>
        </div>

        <div class="box-tools pull-right">
            <form id="f1" action="${pageContext.request.contextPath}/departmentList/findAll.do" method="post">
                <input name="likename" value="${likename}">
                <input type="hidden" name="pageNum" id="pc">
                <input type="hidden" name="pageSize" id="ps">
                <input type="submit" value="搜索">
            </form>

        </div>
        <!--工具栏/-->

        <!--数据列表-->

        <table id="dataList" class="table table-bordered table-striped table-hover dataTable">
            <thead>
            <tr>
                <th class="" style="padding-right:0px;">
                    <input id="selall" type="checkbox" class="icheckbox_square-blue">
                </th>
                <th class="sorting_asc">科室</th>
                <th class="sorting_desc">科室介绍</th>

            </tr>
            </thead>
            <tbody>
            <c:forEach var="department" items="${page.list}">
                <tr>
                    <td>
                        <input type="checkbox" name="cks" value="${department.id}">
                    </td>
                    <td>${department.department_name}</td>
                    <td>${department.department_introduction}</td>
                </tr>
            </c:forEach>


            </tbody>


        </table>
</div>
</div>


<div class="box-footer">
    <div class="pull-left">
        <div class="form-group form-inline">
            当前第${page.pageNum}页/总共${page.pages} 页，共${page.total} 条数据。 每页
            <select class="form-control" id="pageSize">
                <option value="1" ${page.pageSize==1?'selected=selected':''}>1</option>
                <option value="2" ${page.pageSize==2?'selected=selected':''}>2</option>
                <option value="3" ${page.pageSize==3?'selected=selected':''}>3</option>
                <option value="4" ${page.pageSize==4?'selected=selected':''}>4</option>
                <option value="5" ${page.pageSize==5?'selected=selected':''}>5</option>
            </select> 条
        </div>
    </div>

    <div class="box-tools pull-right">
        <ul class="pagination">
            <li>
                <a href="javascript:go(1)" aria-label="Previous">首页</a>
            </li>
            <c:if test="${page.hasPreviousPage}">
                <li><a href="javascript:go(${page.prePage})">上一页</a></li>
            </c:if>

            <li><a href="javascript:go(1)">1</a></li>
            <li><a href="javascript:go(2)">2</a></li>
            <li><a href="javascript:go(3)">3</a></li>
            <li><a href="javascript:go(4)">4</a></li>
            <li><a href="javascript:go(5)">5</a></li>

            <c:if test="${page.hasNextPage}">
                <li><a href="javascript:go(${page.nextPage})">下一页</a></li>
            </c:if>

            <li>
                <a href="javascript:go(${page.pages})" aria-label="Next">尾页</a>
            </li>
        </ul>
    </div>

</div>
<!-- /.box-footer-->

    </div>
</section>



<script src="${pageContext.request.contextPath}/static/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/static/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/static/js/jquery.plugin.min.js"></script>
<script src="${pageContext.request.contextPath}/static/js/jquery.isotope.min.js"></script>
<script src="${pageContext.request.contextPath}/static/js/jquery.magnific-popup.min.js"></script>
<script src="${pageContext.request.contextPath}/static/js/bootstrap-dropdownhover.min.js"></script>
<script src="${pageContext.request.contextPath}/static/js/wow.min.js"></script>
<script src="${pageContext.request.contextPath}/static/js/waypoints.min.js"></script>
<script src="${pageContext.request.contextPath}/static/js/jquery.counterup.min.js"></script>
<script src="${pageContext.request.contextPath}/static/js/main.js"></script>
<script>
    $(document).ready(function() {


    });
    function toAllocationRole(id){
        window.location.href="${pageContext.request.contextPath}/user/toAllocationRole.do?id="+id;

    }
    function go(pageNum){
        $("#pc").val(pageNum);

        var pageSize=$("#pageSize option:selected").val();
        $("#ps").val(pageSize);
        $("#f1").submit();
    }
    $("#pageSize").change(function (){
        var pageSize=$("#pageSize option:selected").val();
        $("#ps").val(pageSize);
        $("#pc").val(${page.pageNum});
        $("#f1").submit();
    })
    $("#toadd").click(function (){
        window.location.href="${pageContext.request.contextPath}/jsp/addDepartment.jsp"
    })

    function fx(){
        var cks=document.getElementsByName("cks");
        for(var i=0;i<cks.length;i++){
            if (cks[i].checked){
                cks[i].checked=false;
            }else {
                cks[i].checked=true;
            }
        }
    }
    function update(){
        var count=0;
        var checkedIds = [];
        var cks=document.getElementsByName("cks")
        for (var i = 0; i < cks.length; i++) {
            if (cks[i].checked) {
                count++;
                checkedIds.push(cks[i].value);
            }
        }
        if (count === 1){
            var id = checkedIds[0];
            console.log("id:",id)
            window.location.href="${pageContext.request.contextPath}/departmentList/findDepartmentById.do?id="+id;
        }else {
            alert("选择一项修改")
        }
    }
    function toDel() {
        var count = 0;
        var cks = document.getElementsByName("cks");
        for (var i = 0; i < cks.length; i++) {
            if (cks[i].checked) {
                count++;
            }
        }
        if (count > 0) {
            if (confirm("确认要删除吗?")) {
                var ids = "";
                for (var i = 0; i < cks.length; i++) {
                    if (cks[i].checked) {
                        ids += cks[i].value + "-";
                    }
                }
                ids = ids.slice(0, -1);
                console.log("IDs to send:", ids);

                $.ajax({
                    url: '${pageContext.request.contextPath}/departmentList/del.do',
                    type: 'POST',
                    data: { ids: ids },
                    success: function() {
                        alert('删除成功');
                        window.location.reload();
                    },
                    error: function() {
                        alert('删除失败');
                    }
                });
            } else {
                alert("已取消");
            }
        } else {
            alert("至少选择一项删除");
        }
    }
</script>
</body>
</html>

